$(document).ready(function () {
    getTreeData()
});

function getTreeData() {
    $.ajax({
        type: "GET",
        url: "/sys/dept/tree",
        success: function (tree) {
            loadTree(tree);
        }
    });
}

function loadTree(tree) {
    $('#deptTree').jstree({
        'core': {
            'data': tree
        },
        "plugins": ["search"]
    });
    $('#deptTree').jstree().open_all();
}

$('#deptTree').on("changed.jstree", function (e, data) {
    if (data.node.id !== -1) {
        parent.loadDept(data.node.id, data.node.text);
        var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
        parent.layer.close(index);
    }
});